<?php

namespace backend\models\site;

use Yii;

/**
 * This is the model class for table "{{%edu_user_course}}".
 *
 * @property integer $user_course_id
 * @property integer $user_id
 * @property integer $course_id
 * @property integer $add_time
 * @property integer $learnedNum
 * @property integer $isLearned
 */
class UserCourser extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user_course}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'course_id', 'add_time', 'learnedNum', 'isLearned'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'user_course_id' => 'User Course ID',
            'user_id' => 'User ID',
            'course_id' => 'Course ID',
            'add_time' => 'Add Time',
            'learnedNum' => 'Learned Num',
            'isLearned' => 'Is Learned',
        ];
    }

	/* 购买课程数  今日 */
	static public function TodayBuycourser($today_start,$today_end)
	{
		return UserCourser::find()
				->where("add_time>= :today_start and add_time<= :today_end",
				[':today_start'=>$today_start,':today_end'=>$today_end])
				->count();
	}

	/* 购买课程数  昨日 */
	static public function YesterdayBuycourser($yesterday_start,$yesterday_end)
	{
		return UserCourser::find()
				->where("add_time>= :yesterday_start and add_time<= :yesterday_end",
				[':yesterday_start'=>$yesterday_start,':yesterday_end'=>$yesterday_end])
				->count();
	}

	/* 完成课时学习数  今日 */
	static public function TodayCoursecomplete($today_start,$today_end)
	{
		return UserCourser::find()
				->where("add_time>= :today_start and add_time <= :today_end and isLearned = :isLearned",
				[':today_start'=>$today_start,':today_end'=>$today_end,':isLearned'=>1])
				->count();
	}

	/* 完成课时学习数  昨日 */
	static public function YesterdayCoursecomplete($yesterday_start,$yesterday_end)
	{
		return UserCourser::find()
				->where("add_time>= :yesterday_start and add_time<= :yesterday_end and isLearned = :isLearned",
				[':yesterday_start'=>$yesterday_start,':yesterday_end'=>$yesterday_end,':isLearned'=>1])
				->count();
	}
}
